package cn.fingersoft.im.glide

import android.app.ActivityManager
import android.content.Context
import cn.fingersoft.im.glide.UnsafeOkHttpClient.Companion.unsafeOkHttpClient
import com.bumptech.glide.Glide
import com.bumptech.glide.GlideBuilder
import com.bumptech.glide.Registry
import com.bumptech.glide.annotation.GlideModule
import com.bumptech.glide.integration.okhttp3.OkHttpUrlLoader
import com.bumptech.glide.load.model.GlideUrl
import com.bumptech.glide.module.AppGlideModule
import java.io.InputStream

/**
 * @author liubinbin
 */
@GlideModule
class MyAppGlideModule : AppGlideModule() {
    override fun applyOptions(context: Context, builder: GlideBuilder) {
        val activityManager = context.getSystemService(Context.ACTIVITY_SERVICE) as ActivityManager
//        if (activityManager != null) {
//            builder.setDefaultRequestOptions(ImageUtil.getOption());
//        }
    }

    override fun registerComponents(context: Context, glide: Glide, registry: Registry) {
        //设置请求方式为okhttp 并设置okhttpClient的证书及超时时间
        registry.replace(GlideUrl::class.java, InputStream::class.java, OkHttpUrlLoader.Factory(unsafeOkHttpClient))
    }
}
